<template>
  <el-button
    v-bind="$attrs"
    :loading="loading"
    @click="handleClick"
  >
    <slot/>
  </el-button>
</template>
<script>
export default {
  name: 'ElLoadingButton',
  props: {
    loadingClick: {
      type: Function,
      required: true
    }
  },
  data() {
    return {
      loading: false
    }
  },
  methods: {
    async handleClick() {
      this.loading = true
      try {
        await this.loadingClick()
      } catch (error) {
        throw new Error(error)
      } finally {
        this.loading = false
      }
    }
    // handleClick() {
    //   this.loading = true
    //   Promise.resolve(this.loadingClick()).catch(error => {
    //     throw new Error(error)
    //   }).finally(e => {
    //     this.loading = false
    //   })
    // }
  }
}
</script>
